package com.gemme.gemme.wode;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.view.SgDDView;
import com.gemme.gemme.view.Topview;
import com.jaeger.library.StatusBarUtil;

import org.json.JSONObject;

import java.util.HashMap;

import androidx.annotation.RequiresApi;

//侧滑删除地址
public class DpjDetailActivity extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dingdan_dpj);
        initTop();
        initView();
        initIntentData();
    }

    int id;
    private void initIntentData() {
        try {

            id = getIntent().getIntExtra("data",-1);
            if(id > -1){
                getData();
            }
        }catch (Exception e){

        }
    }

    private void getData() {
        String url = DataManager.BaseUrl_panghu + "mall/shoporderdetail/" + id;



        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(mContext));
        DataManager.toServer2(mContext, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onResponse(String response) {
                try {

                    JSONObject jsonObject = new JSONObject(response);

                    String data = jsonObject.getJSONObject("data").getString("wholeOrderVo");
                    JSONObject jbInfo = jsonObject.getJSONObject("data").getJSONObject("paddressResquersVo");
                    DingdanListBean.DataBean dataBean = JSON.parseObject(data, DingdanListBean.DataBean.class);
                    String addressee = jbInfo.getString("addressee");
                    String address = jbInfo.getString("address");

                    tv_name.setText(addressee + "");
                    tv_address.setText(address + "");
                    sgDDView.setdata(dataBean);
                    tv_order_id.setText(dataBean.getOrderId() + "");
                    tv_create_time.setText(dataBean.getCreateTime() + "");
                    tv_brand.setText(dataBean.getBrandName());

                    System.out.println("");
                }catch (Exception e){

                }

            }
        });
    }

    SgDDView sgDDView;
    TextView tv_name;
    TextView tv_address;
    TextView tv_order_id;
    TextView tv_create_time;
    TextView tv_brand;
    TextView tv_pingjia;
    private void initView() {
        tv_name = findViewById(R.id.tv_name);
        tv_address = findViewById(R.id.tv_address);
        sgDDView = findViewById(R.id.sgDDView);
        tv_order_id = findViewById(R.id.tv_order_id);
        tv_create_time = findViewById(R.id.tv_create_time);;
        tv_brand = findViewById(R.id.tv_brand);
        tv_pingjia = findViewById(R.id.tv_pingjia);
        RelativeLayout rl_wuliu = findViewById(R.id.rl_wuliu);
        rl_wuliu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mContext,SeeWuliuActivity.class));
            }
        });

        tv_pingjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, EvaluateActivity.class);
                intent.putExtra("data",id);
                startActivity(intent);
            }
        });
    }


    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
        Topview topview = findViewById(R.id.topview);
        topview.setContentText("订单详情");
    }




}